/*
 * Copyright (C) 2017 Pingan, Inc. All Rights Reserved.
 */

package com.pingan.haofang.searchcloud.web.users.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pingan.haofang.gov.sm.account.common.SessionVisitor;
import com.pingan.haofang.gov.sm.account.common.UserThreadContext;
import com.pingan.haofang.searchcloud.common.constants.WebConstants;
import com.pingan.haofang.searchcloud.web.users.vo.VisitorVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户信息Controller
 *
 * @author zhangbi617
 * @date 16/05/2017
 */
@RestController
@RequestMapping(value = WebConstants.WEB_PREFIX + "/session")
@Api(tags = "User.Session", description = "用户会话管理")
public class SessionController {

    @Value("${dashboard.report.env}")
    private String env;

    @ApiOperation(value = "当前用户")
    @GetMapping("visitor")
    public VisitorVo visitor() {
    	SessionVisitor sessionVisitor = UserThreadContext.getSessionVisitor();
        VisitorVo vo = new VisitorVo();
        vo.setUserId(sessionVisitor.getAccountId());
        vo.setUserName(sessionVisitor.getSessionViewDTO().getUsername());
        vo.setRoleId(sessionVisitor.getSessionViewDTO().getIsRoot());
        return vo;
    }

    @ApiOperation(value = "环境")
    @GetMapping("env")
    public String env() {
        return env;
    }
}
